package swa.group22;
import java.util.Collection;

import javax.jws.WebService;

import swa2012.telco.broker.BrokerCallback;
import swa2012.telco.broker.beans.Client;
import swa2012.telco.broker.beans.Message;
import swa2012.telco.broker.beans.ReceiveMessageStatus;

/**
 * Setup for the webservice which implements the BrokerCallback interface.
 * 
 * @author group 22
 *
 */

@WebService(endpointInterface = "swa2012.telco.broker.BrokerCallback")
public class ProviderBrokerCallback implements BrokerCallback {

	private ClientStore clientStore;
	private MessageStore messageStore;
	

	public ProviderBrokerCallback() {
		
	}
	
	/**
	 * Sets clientstore and messagestore objects 
	 * 
	 * @param clientStore
	 * @param messageStore
	 */
	public ProviderBrokerCallback(ClientStore clientStore,
			MessageStore messageStore) {
		
		this.clientStore = clientStore;
		this.messageStore = messageStore;
	}


	@Override
	/**
	 * Adds a Message from the Broker to the local message store
	 * 
	 * @return ReceiveMessageStatus Enum
	 */
	public ReceiveMessageStatus receiveMessage(Message msg) {
		messageStore.addMessage(msg);
		return ReceiveMessageStatus.RECEIVE_MESSAGE_OK; 
	}

	@Override
	/**
	 * Lists all Clients registered at the provider
	 * 
	 * @return Collection of clients
	 */
	public Collection<Client> listClients() {
		Collection<Client> clients = clientStore.getClients();
		
		return clients;
	}

	@Override
	/**
	 * Broker checks with ping() method, whether a connection is open or not
	 * 
	 * @return true
	 */
	public boolean ping() {
		
		return true;
	}

	
	
	
}
